package com.lmt_10;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Room {
    private List<Card> allCards = new ArrayList<>();
    public Room(){
        String []numbers = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
        String []colors = {"红","黄","蓝","绿"};
        int size = 0;
        for (String number : numbers) {
            for (String color : colors) {
                Card card = new Card(number,color,size);
                size++;
                allCards.add(card);
            }
        }
        Card c1 = new Card("","小王",++size);
        Card c2 = new Card("","大王",++size);
        Collections.addAll(allCards,c1,c2);

       // System.out.println(allCards);

        Collections.shuffle(allCards);
        System.out.println("新牌"+allCards);
    }

    public void start() {
        List<Card> p1 = new ArrayList<>();
        List<Card> p2 = new ArrayList<>();
        List<Card> p3 = new ArrayList<>();

        // 发牌
        for (int i =0; i < allCards.size() - 3; i++){
            if (i % 3 == 0)
            {
                p1.add(allCards.get(i));
            }
            else if (i % 3 == 1){
                p2.add(allCards.get(i));
            }
            else {
                p3.add(allCards.get(i));
            }
        }
        sortCards(p1);
        sortCards(p2);
        sortCards(p3);

        System.out.println("p1:  "+p1);
        System.out.println("p2:  "+p2);
        System.out.println("p3:  "+p3);

        List<Card> cards = allCards.subList(allCards.size() - 3, allCards.size());
        System.out.println("底牌"+cards);

        System.out.println("p1抢到地主之后");
        p1.addAll(cards);
        sortCards(p1);
        System.out.println("p1: "+p1);
    }

    private void sortCards(List<Card> p) {
        Collections.sort(p,((o1, o2) -> o1.getSize() - o2.getSize()));
    }
}
